//
//  WSQBaseViewController.m
//  WSQOCTools
//
//  Created by 翁胜琼 on 2018/8/28.
//  Copyright © 2018年 Dev John. All rights reserved.
//

#import "WSQBaseViewController.h"

@interface WSQBaseViewController ()

@property (nonatomic, assign) UIStatusBarStyle sq_statusBarStyle;
@property (nonatomic, assign) BOOL sq_statusBarHidden;

@end

@implementation WSQBaseViewController

- (instancetype)initWithViewModel:(__kindof WSQViewModel *)viewModel
{
    if (self = [super init])
    {
        
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];

    //当你的容器是nav时，布局默认冲navbar的顶部开始，所有的UI元素都向上移动了44px。将edgesForExtendedLayout属性设置成UIRectEdgeNone，布局就会从导航栏下面开始。
    if ([self respondsToSelector:@selector(setEdgesForExtendedLayout:)]) {
        self.edgesForExtendedLayout=UIRectEdgeNone;
    }
    
    if ([self respondsToSelector:@selector(setupUI)])
    {
        // 设置视图
        [self setupUI];
    }
    
    if ([self respondsToSelector:@selector(setupNav)])
    {
        // 设置导航栏
        [self setupNav];
    }
    
    if ([self respondsToSelector:@selector(bindViewModel)])
    {
        // 绑定视图模型
        [self bindViewModel];
    }
}

// MARK: - BindViewModel
- (void)bindViewModel
{
    
}

// MARK: - setupUI
- (void)setupUI
{
    [self setupRootView];
    [self setNeedsStatusBarAppearanceUpdate];
    
    if ([self respondsToSelector:@selector(setupTableView)])
    {
        [self setupTableView];
    }
}

- (void)setupTableView
{
    
}

- (void)setupRootView
{
    self.view.backgroundColor = [UIColor whiteColor];
}

- (void)setupNav
{
    
}

// MARK: - 状态栏设置
- (void)updateStatusBarStyle:(UIStatusBarStyle)statusBarStyle
       shouldStatusBarHidden:(BOOL)hidden
               withAnimation:(BOOL)animation
{
    self.sq_statusBarStyle = statusBarStyle;
    self.sq_statusBarHidden = hidden;
    
    if (animation) {
        [UIView animateWithDuration:0.25 animations:^{
            [self setNeedsStatusBarAppearanceUpdate];
        }];
    }
    else{
        [self setNeedsStatusBarAppearanceUpdate];
    }
}

- (BOOL)prefersStatusBarHidden {
    
    return self.sq_statusBarHidden;
}

- (UIStatusBarStyle)preferredStatusBarStyle {
    
    if (self.sq_statusBarStyle) {
        return self.sq_statusBarStyle;
    } else {
        return UIStatusBarStyleDefault;
    }
}

// MARK: - 设置控制器旋转方向
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
    
    return UIInterfaceOrientationPortrait;
}

// 旋屏支持
- (BOOL)shouldAutorotate
{
    return false;
}

- (void)dealloc {
    
    //NSStringFromSelector返回该方法的方法名
    NSLog(@"Runing %@ %@",[self class], NSStringFromSelector(_cmd));
}





@end
